#ifndef _PREFIX_H_
#define _PREFIX_H_

extern "C" {

#undef BR_NAMESPACE
#define BR_NAMESPACE(funcName) funcName
#define br_thread_local_store BR_NAMESPACE(br_thread_local_store)
#define br_locate BR_NAMESPACE(br_locate)
#define br_locate_prefix BR_NAMESPACE(br_locate_prefix)
#define br_prepend_prefix BR_NAMESPACE(br_prepend_prefix)
#undef SELFPATH
#undef PREFIX
#undef PREFIXDIR
#undef BINDIR
#undef SBINDIR
#undef DATADIR
#undef LIBDIR
#undef LIBEXECDIR
#undef ETCDIR
#undef SYSCONFDIR
#undef CONFDIR
#undef LOCALEDIR
#define SELFPATH  (br_thread_local_store (br_locate ((void *) "")))
#define PREFIX    (br_thread_local_store (br_locate_prefix ((void *) "")))
#define PREFIXDIR (br_thread_local_store (br_locate_prefix ((void *) "")))
#define BINDIR    (br_thread_local_store (br_prepend_prefix ((void *) "", "/bin")))
#define SBINDIR   (br_thread_local_store (br_prepend_prefix ((void *) "", "/sbin")))
#define DATADIR   (br_thread_local_store (br_prepend_prefix ((void *) "", "/share")))
#define LIBDIR    (br_thread_local_store (br_prepend_prefix ((void *) "", "/lib")))
#define LIBEXECDIR  (br_thread_local_store (br_prepend_prefix ((void *) "", "/libexec")))
#define ETCDIR    (br_thread_local_store (br_prepend_prefix ((void *) "", "/etc")))
#define SYSCONFDIR  (br_thread_local_store (br_prepend_prefix ((void *) "", "/etc")))
#define CONFDIR   (br_thread_local_store (br_prepend_prefix ((void *) "", "/etc")))
#define LOCALEDIR (br_thread_local_store (br_prepend_prefix ((void *) "", "/share/locale")))

  const char *br_thread_local_store( char *str );
  char *br_locate( void *symbol );
  char *br_locate_prefix( void *symbol );
  char *br_prepend_prefix( void *symbol, char *path );

#define br_strcat BR_NAMESPACE(br_strcat)
#define br_extract_dir BR_NAMESPACE(br_extract_dir)
#define br_extract_prefix BR_NAMESPACE(br_extract_prefix)
#define BR_SELFPATH(suffix) (br_thread_local_store (br_strcat (SELFPATH, suffix)))
#define BR_PREFIX(suffix) (br_thread_local_store (br_strcat (PREFIX, suffix)))
#define BR_PREFIXDIR(suffix)  (br_thread_local_store (br_strcat (BR_PREFIX, suffix)))
#define BR_BINDIR(suffix) (br_thread_local_store (br_strcat (BINDIR, suffix)))
#define BR_SBINDIR(suffix)  (br_thread_local_store (br_strcat (SBINDIR, suffix)))
#define BR_DATADIR(suffix)  (br_thread_local_store (br_strcat (DATADIR, suffix)))
#define BR_LIBDIR(suffix) (br_thread_local_store (br_strcat (LIBDIR, suffix)))
#define BR_LIBEXECDIR(suffix) (br_thread_local_store (br_strcat (LIBEXECDIR, suffix)))
#define BR_ETCDIR(suffix) (br_thread_local_store (br_strcat (ETCDIR, suffix)))
#define BR_SYSCONFDIR(suffix) (br_thread_local_store (br_strcat (SYSCONFDIR, suffix)))
#define BR_CONFDIR(suffix)  (br_thread_local_store (br_strcat (CONFDIR, suffix)))
#define BR_LOCALEDIR(suffix)  (br_thread_local_store (br_strcat (LOCALEDIR, suffix)))

  char *br_strcat( const char *str1, const char *str2 );
  char *br_extract_dir( const char *path );
  char *br_extract_prefix( const char *path );
}

#endif
